Working with Data sources

Changing an ADO data source location - new methods

In Crystal Reports 8, there are two new methods to add ADO data sources to a report:

In this example, a connection set up through the VB Data Environment is used as a data source. Both methods can be used with either the VB Data Environment or another data source created at runtime.

Option Explicit
Dim CRXReport As New CrystalReport1

The ADO connection to the local database.

Dim cnn1 As ADODB.Connection
Dim datcmd1 As ADODB.Command

Demonstrate the use of AddADOCommand by opening an ADO data command and adding the data source to the report.

Private Sub cmdADO_Click()
    Dim strCnn As String

Open the data connection.

    Set cnn1 = New ADODB.Connection
    strCnn = "Provider=MSDASQL;Persist Security Info=False;Data 
Source=Xtreme Sample Database;Mode=Read"
    cnn1.Open strCnn

Create a new instance of an ADO command object.

    Set datcmd1 = New ADODB.Command
    Set datcmd1.ActiveConnection = cnn1
    datcmd1.CommandText = "Customer"
    datcmd1.CommandType = adCmdTable

Add the datasource to the report.

    CRXReport.Database.AddADOCommand cnn1, datcmd1
End Sub

Adding a data source and a field using AddOLEDBSource

This section demonstrates the use of AddOLEDBSource. One line of code:

In this example, we are using an OLEDB source created in a VB Data Environment.

CRXReport.Database.AddOLEDBSource DataEnvironment1.Connection1,"Customer"

Setting the data source for a subreport

This section describes how to change the database location for different types of data sources

You change the database location (change the data source) for a subreport in much the same way as you set the database location for the main report. Before you can change the database location for a subreport, you first need to open the subreport. For more information, see Referencing objects in a subreport.

Once you have opened the subreport you can change the database location. The following examples show you how to do that for a variety of different types of data sources.



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com